INCLUDE_FLAGS = -I. \
				-I./log \
				-I./iolib \
				-I./http \
				-I./filter

CFLAGS	      = $(INCLUDE_FLAGS) -Wall -g

ifeq ($(arch),)
	CC	  		  = gcc
	AR			  = ar
else
	CC	  		  = arm-linux-gcc
	AR			  = arm-linux-ar
	STRIP		  = arm-linux-strip
endif

LFLAGS 		  = -L./iolib -lio \
                -L./log -llog \
                -L./http -lhttp \
                -L./filter -lfilter

SHELL 		 = /bin/bash
SUBDIRS 	 = 	log \
				iolib \
				http \
				filter

TARGET = miniHttpServer

export CC
export AR

SOUCE_FILES = $(wildcard *.c)
OBJS = $(patsubst %.c,%.o,$(SOUCE_FILES))

%.o : %.c %.h
	$(CC) -c $(CFLAGS) $< -o $@

$(TARGET): $(OBJS) libs
	$(CC) $(OBJS) -o $@ $(CFLAGS) $(LFLAGS)

libs:
	@ for subdir in $(SUBDIRS); do \
        (cd $$subdir && $(MAKE)); \
	done

.PHONY:clean update debug strip tags

strip: $(TARGET)
	$(STRIP) $(TARGET)

tags:
	ctags -R *

clean:
	$(RM) $(TARGET) $(OBJS)
	@ for subdir in $(SUBDIRS); do \
        (cd $$subdir && $(MAKE) clean); \
    done
